package com.qf.ssm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.ssm.mapper.UserMapper;
import com.qf.ssm.pojo.User;
import com.qf.ssm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class UserServiceImpl implements UserService {

    private UserMapper userMapper;

    @Autowired
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public void addUser(User user) {
        //先判断
        //开启事务，交给aop处理
        userMapper.addUser(user);
        //提交事务,交给aop处理

    }

    @Override
    public User findUserById(Long id) {
        User user = userMapper.findUserById(id);
        return user;
    }

    @Override
    public PageInfo<User> findUserByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<User>userList=userMapper.findAllUsers();
        PageInfo<User>pageInfo=new PageInfo<>(userList);
        return pageInfo;
    }


}
